package obiektyturystyczne;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**

 @author Tomek
 */
public class SqlQueries {

	static String select = "SELECT * FROM ";
	public static Statement statement;

	public static ResultSet Wszystkie(String tableName) {
		try {
			return statement.executeQuery(select + tableName);
		} catch (SQLException ex) {
			return null;
		}
	}

	public static int Count(String tableName) {
		try {
			ResultSet result = statement.executeQuery("SELECT count(*) from " + tableName);
			result.next();
			return result.getInt("count");
		} catch (SQLException ex) {
			return -1;
		}
	}

	public static ResultSet Insert(String tabela, String kolumny, String wartosci, String returning) throws SQLException {
		String query = "Insert into " + tabela;
		if (!"".equals(kolumny) && kolumny != null) {
			query += " (" + kolumny + ") ";
		}
		query += " VALUES (" + wartosci + ")";
		System.out.println(query + ";");
		if (!"".equals(returning)) {
			query += " returning " + returning;
		}    
		statement.execute(query);
		if (!"".equals(returning) && returning != null) {
			return statement.getResultSet();
		}
		return null;
	}
}
